package hospital.utils;

import hospital.common.utils.MD5;
import hospital.service.HospitalSetService;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author
 * @description: 验证医院签名的工具类
 */
@Slf4j
public final class manageUtils {

    /**
     * @Author yang
     * @Description //TODO 验证医院的签名是否正确
     * @Param
     * @return
     **/
    public static boolean checkSignKey(Map<String, Object> parameterMap, HospitalSetService hospitalSetService){
        //判断医院的签名是否一致，传入的sign为MD5加密后的str
        //是否和 再yygh_hosp数据库中 相同的医院的sign，进行MD5加密后是否一致
        //1.获取请求中的sign
        String requestSign = (String) parameterMap.get("sign");

        //2.获取请求的hoscode获取数据库中sign,并进行MD5的加密
        String requestHoscode = (String) parameterMap.get("hoscode");
        String hospitalSign=hospitalSetService.getSignByHoscode(requestHoscode);
        String hospitalMD5Sign = MD5.encrypt(hospitalSign);

        //比较两个sign
        if(!requestSign.equals(hospitalMD5Sign)){
            return false;
        }else {
            return true;
        }
    }
}
